/**
 * Author: Shen Yanqiu
 * Date: 2017-12-18
 * Time: 13:42
 *
 */
import { routerRedux } from "dva/router";
import modelExtend from 'dva-model-extend';
import { pageModel } from '../common';
import { delay, routerTool } from "utils";
// import { getActivityList, getActivityDetails } from './../../services/activity';

export default modelExtend(pageModel, {
  namespace: 'accountmanagement',

  state: {

  },

  subscriptions: {
    setup ({ dispatch, history }) {
      let time = {
        baseinfo: 0,
        mymember: 0,
        changepassword: 0,
      };
      history.listen((location) => {
        console.log(location.pathname);
        if (location.pathname === routerTool.getPathByName('AccountManagement')) {
          dispatch(
            routerTool.redirectTo({
              name: 'AccountManagementBaseInfo',
            })
          );
        }
        if (location.pathname === routerTool.getPathByName('AccountManagementBaseInfo')) {
          if (time.baseinfo > 0) {
            return;
          }
          time.baseinfo += 1;
          dispatch({ type: 'laterSomeSecond' });
        }
        if (location.pathname === routerTool.getPathByName('AccountManagementMyMember')) {
          if (time.mymember > 0) {
            return;
          }
          time.mymember += 1;
          dispatch({ type: 'laterSomeSecond' });
        }
        if (location.pathname === routerTool.getPathByName('AccountManagementChangePassword')) {
          if (time.changepassword > 0) {
            return;
          }
          time.changepassword += 1;
          dispatch({ type: 'laterSomeSecond' });
        }
      });
    },
  },

  effects: {
    * laterSomeSecond ({ payload = {} }, { put, call }) {
      yield delay(500);
    },
  },

  reducers: {
    update (state, { payload }) {
      return { ...state, ...payload };
    },
  },
});
